fix(encryption): Refactor EncryptionWrapper, fix zero-byte size, add S3 tests#57279
fix(encryption): Refactor EncryptionWrapper, fix zero-byte size, add S3 tests#57279cuppett wants to merge 5 commits intonextcloud:masterfrom
Conversation
0a01f11 to
fd39e51
Compare
f4f2d21 to
1a81edd
Compare
|
Failing test seems related. e.g. |
This is not true, the home storage is mounted at |
fcadd6f to
c0c3ae6
Compare
30903a9 to
4dc1def
Compare
f723818 to
1e1aeaa
Compare
|
Working through propagating getBoolVal everywhere. |
|
Your tests fail bc the IAppConfig methods are called before the Nextcloud install is finished. The old code handled that gracefully, but the current code does not. Please change your code to wrap the IAppConfig calls in |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 30 out of 30 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@miaulalala Okay, I'm back! Did the things to convert to a boolean throughout for that app config setting. |
PR is looking good, tests pass. @artonge or @CarlSchwan can either of you review? |
@artonge A bulk of the changes are in testing. The logic changed by +222 / -65. The rest is testing. Teasing that apart will be challenging logically. I think I could rearrange individual commits depending on how you want to review it. |
|
Pushed through rebase to newest master |
|
Rebase only. |
Your summary in your first comment suggests that you identified key changes, that would probably be a good way to split it.
Indeed, 18 commits seem like a lot compared to your summary. Maybe to give a bit of context, we are receiving an increasing number of large PRs, which takes a lot of time to review, splitting the PR into manageable chunks would drastically help us to review it. Some can probably be quickly reviewed and merged, other might require some discussion. |
Let me squash them into the 5 passes. Waiting 5 months to get these first couple reviews (or peeks) isn't something I want to repeat. :) |
Rewrite conditional flow to use early-return guards: skip IDisableEncryptionStorage, skip the root mount, respect encryptHomeStorage for HomeMountPoints. Uses IAppConfig for the encryptHomeStorage setting with a legacy string fallback for the upgrade window. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Cuppett <steve@cuppett.com>
Files with 0 bytes no longer incorrectly report as 8192 bytes. Widens unencryptedSize to ?int, fixes verifyUnencryptedSize to compare against header size instead of 0, and corrects Scanner to populate unencrypted_size on initial upload. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Cuppett <steve@cuppett.com>
…rage Comprehensive tests covering encryption with S3 as primary storage backend, including upload/download, multipart, migration detection, and key validation. EncryptionTrait updated to use IAppConfig and validate share/master keys on setup. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Cuppett <steve@cuppett.com>
Add global encryption teardown to TestCase base class so encryption state does not leak between test suites regardless of which tests ran earlier. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Cuppett <steve@cuppett.com>
… with repair step Switch all encryption config reads/writes from deprecated string-typed IConfig to bool-typed IAppConfig (getValueBool/setValueBool). Adds RetypeEncryptionConfigKeys repair step to retype existing string values to bool on upgrade. Includes lazy IAppConfig resolution in Manager and AppConfigTypeConflictException fallbacks throughout for safety during the upgrade window. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Cuppett <steve@cuppett.com>
|
@artonge I got it squashed to 5 discrete commits. Additional commits were mostly fix/patches for tests. Combined no 1 and 2 from summary, but 5th commit is the pervasive IAppConfig bool usage throughout and fixups. Waiting on tests now. Thanks! |
Related Issue AnalysisReviewed open issues related to S3 encryption and zero-byte file problems. This PR addresses or is relevant to the following: Fully Fixed#58778 — After Root cause: How this PR fixes it: All Enable/Disable/DecryptAll commands now use Partially Fixed / Directly Related#41992 — Server-side encryption does not encrypt files with S3 primary storage Files upload to S3 but are NOT encrypted (only very small text files encrypt, larger files remain unencrypted). What this PR fixes: The EncryptionWrapper conditional flow is refactored into clear early-return guards. The What remains: If the encryption module's #59635 — Config for files_external mount option "encryption" is not respected External S3 mount with "Activate Encryption" = false still encrypts files when SSE is globally enabled. What this PR fixes: The EncryptionWrapper now has a clear guard-chain pattern with early returns. The What remains: The per-mount "Activate Encryption" toggle for #58239 — Regenerating metadata with SSE serves files encrypted (not decrypted) After What this PR fixes: The Scanner now correctly preserves What remains: If the metadata scan resets the |
|
Fixes #58778 |
S3 Encryption Verification — Real AWS S3 BucketRan the full S3 encryption test suite against a real AWS S3 bucket (us-east-1) to verify the fix for #41992 ("Server side encryption does not encrypt files with S3 primary storage"). Setup
Results
Addressing #41992The core symptom in #41992 was: "Files will sync and upload to the S3 provider but are not encrypted, unless they are very small." — specifically 8MB+ files remained unencrypted. The Three assertions prove encryption is working end-to-end:
This branch fully addresses #41992 for all file sizes including multipart uploads. |
Analysis: #59635 — Per-mount encryption toggle not respectedResult: Not fixed by this branch, but root cause identifiedThe per-mount "Activate Encryption" toggle failing is a separate bug in Root cause
public function setOption(int $mountId, string $key, string $value): void {
// ...
->setValue('value', $builder->createNamedParameter(json_encode($value), ...))When called with foreach ($changedOptions as $key => $value) {
$this->dbConfig->setOption($id, $key, $value); // $value is bool false
}PHP silently coerces Traced end-to-end:
What would fix it: Change VerificationConfirmed against a live Nextcloud 34 install with S3 as primary storage: After StatusThis PR's |
|
@cuppett please, cleanup that noise, this is the opposite of what would be respectful to us. I assume you did not even took the time to double-check those outputs, why would we? I am asking you again to make it easy for us to review your changes, split your PR, give us consise summaries that go straight to the point, not AI generated rivers of text. |
Okay, I'll sequence them and pop the refs in here for lineage. Easy enough now with the squashed ones to land in a good order. |
Summary
This PR makes several improvements to Nextcloud's encryption infrastructure:
encryptHomeStoragesetting for home storage mountsChanges
Code Fixes
lib/private/Encryption/EncryptionWrapper.phpRefactored storage wrapper logic:
encryptHomeStoragesetting on HomeMountPoint mountslib/private/Files/Cache/CacheEntry.php&lib/private/Files/FileInfo.phpFixed zero-byte file size reporting:
> 0check that caused 0-byte encrypted files to report as 8192 bytes (encryption header size)Test Infrastructure
New:
tests/lib/Files/ObjectStore/S3EncryptionTest.php(493 lines)Comprehensive S3 encryption test suite covering:
New:
tests/lib/Files/ObjectStore/S3EncryptionMigrationTest.php(270 lines)Migration scenario tests:
encryption:encrypt-alltests/lib/TestCase.php+ 5 encryption test filesFixed test pollution:
MultiKeyEncryptExceptionfailures from state leakage between testsFiles Changed
lib/private/Encryption/EncryptionWrapper.phplib/private/Files/Cache/CacheEntry.phplib/private/Files/FileInfo.phptests/lib/TestCase.phptests/lib/Encryption/EncryptionWrapperTest.phptests/lib/Files/ObjectStore/S3EncryptionTest.phptests/lib/Files/ObjectStore/S3EncryptionMigrationTest.phpapps/Backward Compatibility
✅ Fully backward compatible
encryptHomeStoragesetting defaults to enabled ('1')Testing
Run the S3 encryption tests: